/**************************************************************************************
* Component of simpleRTJ regression tests.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Created by:
*       RTJ Computing
**************************************************************************************/
public class TestInt
{
    public static void test() throws Exception
    {
       //test overwrap
       int t = 0x7fffffff-1;
       t++;
       if (t != 0x7fffffff) throw new Exception("TI1");
       t++;
       if (t != 0x80000000) throw new Exception("TI2");

       //shift tests
       t = 4;
       t = t << 1;
       if (t != 8) throw new Exception("TI3");

       t = t >> 2;
       if (t != 2) throw new Exception("TI4");

       //division test
       t = 4;
       if (t >> 1 != t / 2) throw new Exception("TI5");
       if (t / 3 != 1) throw new Exception("TI6");
       if (t / 5 != 0) throw new Exception("TI7");

       //multiplication test
       if (t << 2 != t * 4) throw new Exception("TI8");
       if (t * 3 != 12) throw new Exception("TI9");

       //modulus test
       if (t % 3 != 1) throw new Exception("TI10");
       if (t % 4 != 0) throw new Exception("TI11");
       if (t % 5 != 4) throw new Exception("TI12");

       //unsigned right shift test
       t = -1;
       if (t >>> 4 == t >> 4) throw new Exception("TI13");

       //cast test
       t = 4;
       if ((float)t != 4.0F) throw new Exception("TI14");
       if ((byte)t != (byte)4) throw new Exception("TI15");
       t = -1;
       if ((byte)t != (byte)0xff) throw new Exception("TI16");
       if ((short)t != (short)0xffff) throw new Exception("TI17");

       //addition test
       if (t + 1 != 0) throw new Exception("TI18");
       if (t + 2 != 1) throw new Exception("TI19");

       //subtraction test
       if (t - 1 != -2) throw new Exception("TI20");

       //bitoperations test
       t = 4;
       t = t & 5;
       if (t != 4) throw new Exception("TI21");
       t = t | 5;
       if (t != 5) throw new Exception("TI22");
       t = t ^ 9;
       if (t != 12) throw new Exception("TI23");

       //order of evaluation test
       t = 4;
       t = (t + 2)/3;
       if (t != 2) throw new Exception("TI24");
       t = t + t / 2;
       if (t != 3) throw new Exception("TI25");
       t = (t + 1) * 2;
       if (t != 8) throw new Exception("TI26");
       t = t - t/2;
       if (t != 4) throw new Exception("TI27");
       t = 2 << t / 4;
       if (t != 4) throw new Exception("TI28");
       t = t & 4 << 2 / 4;
       if (t != 4) throw new Exception("TI29");
       t = t | 5 << 2 / 4;
       if (t != 5) throw new Exception("TI30");

       //assignment
       t = 9;
       t += (t=3);
       if (t != 12) throw new Exception("TI31");
       t = 9;
       t = t + (t = 3);
       if (t != 12) throw new Exception("TI32");
   }
}
